
  <template>
  <div class="bf-commont-template">
    <!-- 参数维护 -->
    <div class="clearfix bf-top-button">
      <div class="float-l">
        <el-button @click="showAdd" type="primary">新增</el-button>
      </div>
      <div class="float-r">
        <div class="float-l">
          <el-input placeholder="请输入搜索内容" prefix-icon="el-icon-search" v-model="searchData" @keyup.enter.native="quickSearch"></el-input>
        </div>
        <div class="float-l padding-l">
          <el-button @click="showSearch" type="primary">高级筛选</el-button>
        </div>
      </div>
    </div>

    <bf-table :data="userData" :setting="listSetting" :rowAction="rowAction" @editSubmit="editSubmit" @pageChange="pageChange" ref="table"></bf-table>
    <!-- 添加 -->
    <bf-table-edit :editForm='listSetting' :title="'新增'" ref='addRosterRef' @formSubmit='addSubmit' :editRules="addRules"></bf-table-edit>
    <!-- 高级搜索 -->
    <bf-table-search :editForm='listSetting' :title="'高级搜索'" ref='searchRosterRef' @formSubmit='searchRosterSubmit'></bf-table-search>
    <!-- 编辑 -->
    <bf-table-edit :editForm='editSetting' :title="'编辑'" ref='editRosterRef' @formSubmit='editRosterSubmit' :editRules="addRules">></bf-table-edit>
    <!--详情-->
    <bf-table-detail ref="bfTableDetail" :title="'详情'" :editForm="listSetting"></bf-table-detail>

  </div>
</template>
<script>
import {
  listSetting,
  editSetting
} from './table.setting.js'
import { updatePar, deleteApply, getVacationApplyList, getUserInFo, addVacationApply } from './api.js'
export default {
  data() {
    return {
      searchData: '',
      userData: {
      },
      rowAction: [
        {
          label: '查看',
          click: (item) => {
            this.findDetailById(item.scope.row, this.$refs.bfTableDetail.show)
          }
        },
        {
          label: '编辑',
          click: (item) => {
            this.findDetailById(item.scope.row, this.$refs.editRosterRef.show)
          }
        },
        {
          label: '删除',
          click: (item) => {
            this.$refs.table.showDelete(item)
          }
        }
      ],
      listSetting: listSetting,
      editSetting: editSetting,
      addRules: {
        itemCode: [
          { required: true, message: '请输入枚举项代码', trigger: 'blur' }
        ],
        paramCode: [
          { required: true, message: '请选择参数类型', trigger: 'blur' }
        ],
        itemText: [
          { required: true, message: '请输入枚举项名称', trigger: 'blur' }
        ],
        seqno: [
          { required: true, message: '请输入排序', trigger: 'blur' }
        ]
      }
    }
  },
  mounted: function() {
    this.searchList();
  },
  methods: {
    searchList(form) {
      if (!form) {
        form = {
          page: 1,
        }
      }
      getVacationApplyList(form).then((response) => {
        this.userData = response
      })
    },
    /**
 * 高级搜索
 */
    searchRosterSubmit(form) {
      this.searchList(form)
      this.$refs.searchRosterRef.hiden()
    },
    /**
 * 新增
 */
    addSubmit(form) {
      addVacationApply(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功!',
            type: 'success'
          })
          this.searchList()

          this.$refs.addRosterRef.hiden()
        }
      })
    },
    /**
     * 编辑保存
     */
    editRosterSubmit(form) {
      updatePar(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功!',
            type: 'success'
          })
          this.$refs.editRosterRef.hiden()

          this.searchList()
        }
      })
    },
    findDetailById(data, showCall) { // 详情
      showCall(data)
    },
    editSubmit(params, formType, formList) {
      if (formType === 'delete') {
        this.deleteItem(params.row.paramCode, params.row.itemCode)
      }
    },

    deleteItem(paramCode, itemCode) {
      const para = {
        paramCode: paramCode,
        itemCode: itemCode

      }
      deleteApply(para).then((response) => {
        if (response.success) {
          this.$message({
            message: '删除成功!',
            type: 'success'
          })
          this.searchList()
        }
      })
    },
    pageChange(pageObj) {
      // console.log(pageObj)
      this.searchList(pageObj)
    },
    showSearch() {
      this.$refs.searchRosterRef.show()
    },
    showAdd() {
      getUserInFo().then((response) => {
        // console.log(response.data)
        this.$refs.addRosterRef.show(response.data)
        // console.log(response.data)
        // this.$refs.addRosterRef.show()
      })
    },
    quickSearch() {
      const params = {
        paramCode: this.searchData
      }
      this.searchList(params)
    }
  }
}
</script>

<style scoped>

</style>
